package com.demo.gulimall.product.controller;

import com.demo.gulimall.common.utils.R;
import com.demo.gulimall.product.entity.SkuInfo;
import com.demo.gulimall.product.service.SkuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * @author Chen Yuan
 * @create 2023-06-19  16:34
 */
@RestController
@RequestMapping("/product/skuinfo")
public class SkuInfoController {
	@Autowired
	private SkuInfoService skuInfoService;

	@GetMapping("/{skuId}")
	public R<SkuInfo> skuInfo(@PathVariable("skuId") Long skuId){
		SkuInfo skuInfo = skuInfoService.getById(skuId);
		return R.ok(skuInfo);
	}

	@GetMapping("/price")
	public R<BigDecimal> getSkuPriceById(@RequestParam("skuId") Long skuId){
		SkuInfo skuInfo = skuInfoService.getById(skuId);
		return R.ok(skuInfo.getPrice());
	}
}
